import inherits from 'inherits';

import PropertiesActivator from 'bpmn-js-properties-panel/lib/PropertiesActivator';


import idProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/IdProps';
import nameProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/NameProps';
import processProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/ProcessProps';
import FieldInjectionProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/FieldInjectionProps';
import serviceTaskDelegateProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/ServiceTaskDelegateProps';
import userTaskProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/UserTaskProps';
import scriptProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/ScriptTaskProps';
import linkProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/LinkProps';
import callActivityProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/CallActivityProps';
import eventProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/EventProps';
import errorProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/ErrorEventProps';
import conditionalProps from 'bpmn-js-properties-panel/lib/provider/camunda/parts/ConditionalProps';
import startEventInitiator from 'bpmn-js-properties-panel/lib/provider/camunda/parts/StartEventInitiator';


function createGeneralTabGroups(element, bpmnFactory, canvas, elementRegistry, translate) {

	var generalGroup = {
		id: 'general',
		label: '常规',
		entries: []
	};
	idProps(generalGroup, element, translate);
	nameProps(generalGroup, element, bpmnFactory, canvas, translate);
	processProps(generalGroup, element, translate);

	var detailsGroup = {
		id: 'details',
		label: '详情',
		entries: []
	};
	//主要用的是serviceTaskDelegateProps
	serviceTaskDelegateProps(detailsGroup, element, bpmnFactory, translate);
	userTaskProps(detailsGroup, element, translate);
	scriptProps(detailsGroup, element, bpmnFactory, translate);
	linkProps(detailsGroup, element, translate);
	callActivityProps(detailsGroup, element, bpmnFactory, translate);
	eventProps(detailsGroup, element, bpmnFactory, elementRegistry, translate);
	errorProps(detailsGroup, element, bpmnFactory, translate);
	conditionalProps(detailsGroup, element, bpmnFactory, translate);
	startEventInitiator(detailsGroup, element, translate);

	return [
		generalGroup,
		detailsGroup
	];
}

function createAuthorityTabGroups(element, bpmnFactory, translate) {
	var editAuthorityGroup = {
		id: 'edit-authority',
		label: '字段注入',
		entries: []
	}

	// 每个属性都有自己的props方法
	FieldInjectionProps(editAuthorityGroup, element, bpmnFactory, translate);
	// OtherProps1(editAuthorityGroup, element);
	// OtherProps2(editAuthorityGroup, element);

	return [
		editAuthorityGroup
	];
}
// 这里是要用到什么就引入什么
export default function AuthorityPropertiesProvider(
	eventBus, bpmnFactory, canvas,
	elementRegistry, translate
) {
	PropertiesActivator.call(this, eventBus);

	this.getTabs = function (element) {
		var generalTab = {
			id: 'general',
			label: '常规',
			groups: createGeneralTabGroups(element, bpmnFactory, canvas, elementRegistry, translate)
		};

		var authorityTab = {
			id: 'authority',
			label: '字段注入',
			groups: createAuthorityTabGroups(element, bpmnFactory, translate)
		};
		return [
			generalTab,
			authorityTab
		];
	}
}
AuthorityPropertiesProvider.$inject = ['eventBus', 'bpmnFactory', 'canvas', 'elementRegistry', 'translate']
inherits(AuthorityPropertiesProvider, PropertiesActivator);